import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { visualizer } from 'rollup-plugin-visualizer';
import viteCompression from 'vite-plugin-compression';
import { viteMockServe } from 'vite-plugin-mock' 
import path from 'path'; 
import { minifyHtml, injectHtml } from 'vite-plugin-html';
import styleImport from 'vite-plugin-style-import';
 
export default defineConfig(({ command, mode }) =>{return ({
  base:'/teacherCharge/', 
  css: {
    preprocessorOptions: {
      scss: { 
      },
      less: {
        // modifyVars: {
        //   hack: `true; @import (reference) "${path.resolve("src/assets/css/base.less")}"`,
        // },
        javascriptEnabled: true,
      },
    }
  },
  optimizeDeps: { 
  },
  plugins: [
    vue(),
    vueJsx(),
    styleImport({
      libs: [
        {
          libraryName: 'vant',
          esModule: true,
          resolveStyle: (name) => path.resolve(__dirname, 'node_modules/') + `/vant/es/${name}/style`,
        },
        // {
        //   libraryName: '@arco-design/web-vue',
        //   esModule: true,
        //   resolveStyle: (name) => {
        //     // css
        //     return path.resolve(__dirname, 'node_modules/')+`/@arco-design/web-vue/es/${name}/style/css.js` 
        //     // less
        //     //return path.resolve(__dirname, 'node_modules/')+`/@arco-design/web-vue/es/${name}/style/index.js`
        //   },
        // }
      ],
    }),
    viteMockServe({
      // default
      mockPath: './src/mock/',
      supportTs:true,
      localEnabled: mode === 'mock',
    }),
    viteCompression(),
  ],
  resolve: {
    alias: [
      { find: "@", replacement: path.resolve(__dirname, 'src') }
    ],
  },
  build: {
    minify: true,
    rollupOptions: {
      
        input: {
            index: path.resolve(__dirname, 'htmlEnter/index.html'),//数据看板
            crmIndex: path.resolve(__dirname, 'htmlEnter/crm.html'),
            correction: path.resolve(__dirname, 'htmlEnter/correction.html'),//批改
            newHope: path.resolve(__dirname, 'htmlEnter/correction.html'),//新希望
        },
      plugins: [

        visualizer(
          {
            filename: path.resolve(__dirname, 'dist/stats.html'),
            template: 'treemap',
            sourcemap: true
          }
        )
      ],
      output: {
        namespaceToStringTag: true // close this option, so that router dynamic import will result "Cannot read property 'toStringTag' of undefined". reference: https://github.com/vitejs/vite/issues/1921
      }
    },
    sourcemap: true
  },
  server: {
    port: 4000,
    proxy: {
      '/crm-admin': {
        target: 'http://wtest.xiwang.com',
        changeOrigin: true,
      },
      '/xuefu': {
        // target: 'https://w.xiwang.com/',
        target: 'https://wtest.xiwang.com/',
        changeOrigin: true,
      }
    }
  }
})});
